package com.app.view.component.room.exps 
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	import com.peachcastle.core.Display;
	
	import com.app.model.data.LevelData;
	
	import com.peachcastle.debug.Log;
	
	/**
	 * ...
	 * @author kevin
	 */
	public class ExpsManager extends Display 
	{
		private static const SEAT_MAX_COUNT:int = 8;
		
		private var _usersExps:Array = null;
		
		private var _upgradeLevel:UpgradeLevel = null;
		
		private var _background:Sprite = null;
		
		private var _isback:Boolean = false;
		private var _stageWidth:Number = 0;
		private var _stageHeight:Number = 0;
		
		public function ExpsManager(ui:MovieClip = null, isback:Boolean = false, stageWidth:Number = 0, stageHeight:Number = 0) 
		{
			_isback = isback;
			_stageWidth = stageWidth;
			_stageHeight = stageHeight;
			
			super(ui);
		}
		
		override protected function initialization():void 
		{
			super.initialization();

			_usersExps = [];
			for (var i:int = 1; i <= SEAT_MAX_COUNT; i++)
			{
				_usersExps[i] = new ExpView(assest["increase_exp_" + i]);	
			}
			
			_upgradeLevel = new UpgradeLevel(assest["mc_upgrade_level"]);
		}
		
		public function updateExp(seatid:int, increaseExp:int, isNewLevel:Boolean = false, levelData:LevelData = null):void
		{
			if (increaseExp > 0) ExpView(_usersExps[seatid]).onExpShow(increaseExp);
			if (isNewLevel)
			{
				showLevelUpgrade();
			}
		}
		
		public function showLevelUpgrade():void
		{
			_upgradeLevel.show();
		}
		
		private function showBack():void
		{
			if (!_isback) return;
			_background = new Sprite();
			_background.graphics.beginFill(0x000000, .5);
			
			_background.graphics.drawRect(0, 0, _stageWidth, _stageHeight);
			_background.graphics.endFill();
			
			assest.parent.addChild(_background);
		}
	}

}